package horde

import "event-chain/core/common"

type IAlter[T any, K comparable] interface {
	common.IOnce
	Handle(T, int) T
	GetKey(T) K
}

type Alter[T any, K comparable] struct {
	common.One
	handle func(T, int) T
	getKey func(T) K
}

func NewAlter[T any, K comparable](getKey func(T) K, handle func(T, int) T, once bool) *Alter[T, K] {
	res := &Alter[T, K]{handle: handle, getKey: getKey}
	res.SetOnce(once)
	return res
}

func (a *Alter[T, K]) Handle(data T, i int) T {
	return a.handle(data, i)
}

func (a *Alter[T, K]) GetKey(data T) K {
	return a.getKey(data)
}
